#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/gpio.h>
#include <linux/input.h>
#include <linux/gpio_keys.h>
#include <cfg_type.h>

#define BUTTON_00_PIN	(PAD_GPIO_B + 30)
#define BUTTON_01_PIN	(PAD_GPIO_B + 31)
#define BUTTON_02_PIN	(PAD_GPIO_B + 9)
#define BUTTON_03_PIN	(PAD_GPIO_A + 28)
#define BUTTON_04_PIN	(PAD_GPIO_ALV + 0)
#define BUTTON_05_PIN	(PAD_GPIO_ALV + 5)

static struct gpio_keys_button gpio_buttons[] = {
	[0] = {
		.code		= KEY_UP,
		.gpio		= BUTTON_00_PIN,
		.active_low	= 1,
		.desc		= "Up",
		.wakeup		= 1,
	},

	[1] = {
		.code		= KEY_DOWN,
		.gpio		= BUTTON_01_PIN,
		.active_low	= 1,
		.desc		= "Down",
		.wakeup		= 1,
	},

	[2] = {
		.code		= KEY_LEFT,
		.gpio		= BUTTON_02_PIN,
		.active_low	= 1,
		.desc		= "Left",
		.wakeup		= 1,
	},

	[3] = {
		.code		= KEY_RIGHT,
		.gpio		= BUTTON_03_PIN,
		.active_low	= 1,
		.desc		= "Right",
		.wakeup		= 1,
	},

	[4] = {
		.code		= KEY_POWER,
		.gpio		= BUTTON_04_PIN,
		.active_low	= 1,
		.desc		= "Power",
	},

	[5] = {
		.code		= KEY_WAKEUP,
		.gpio		= BUTTON_05_PIN,
		.active_low	= 1,
		.desc		= "wakeup",
		.wakeup		= 0,
	},
};

static struct gpio_keys_platform_data buttons_data = {
	.buttons	= gpio_buttons,
	.nbuttons	= ARRAY_SIZE(gpio_buttons),
};

static void buttons_release(struct device *devp)
{
	struct platform_device *pdev;

	pdev = container_of(devp, struct platform_device, dev);
	printk("Name:%s, removed.\n", pdev->name);
}

static struct platform_device gpio_input = {
	.name	= "gpio-keys",
	.id	= -1,
	.dev	= {
		.platform_data	= &buttons_data,
		.release	= buttons_release,
	},
};

static int __init gpio_input_init(void)
{
	int ret;

	ret = platform_device_register(&gpio_input);

	return 0;
}

static void __exit gpio_input_exit(void)
{
	platform_device_unregister(&gpio_input);
}

module_init(gpio_input_init);
module_exit(gpio_input_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("XXX");
